package com.deyuanyun.pic.insp.controller;

import com.deyuanyun.pic.common.tool.CheckHandler;
import com.deyuanyun.pic.common.tool.ExceplImportCheck;
import com.deyuanyun.pic.common.util.RequestUtil;
import com.deyuanyun.pic.common.util.ResponseUtil;
import com.deyuanyun.pic.common.util.UploadUtil;
import com.deyuanyun.pic.common.util.ajax.AjaxSupport;
import com.deyuanyun.pic.insp.service.inspresult.InspCommService;
import com.deyuanyun.pic.settings.controller.AbstractBaseController;
import com.deyuanyun.pic.insp.service.inspresult.MetalLossService;
import com.deyuanyun.pic.settings.service.pipe.PipeLocationService;
import com.deyuanyun.pic.settings.support.biz.CodeUtil;
import jxl.read.biff.BiffException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 内检测 公共接口2
 *
 * @author       // scalpel.王敏
 * @version      // [v1.0] 创建时间（2016/6/12 10:34）
 * @see         // 引用的类
 * Method List:
 *         1.----------------
 *         2.----------------
 * History:                           // 历史修改记录           (如果有修改别人的类，必须)   [修改人][时间][修改描述]
 */

@Controller
public class InspCommController extends AbstractBaseController {

	@Resource
	MetalLossService metalLossService;

	@Resource
	PipeLocationService pipeLocationService;

	@Resource
	InspCommService inspCommService;
	/**
	 * 
	  * 查询 检测任务管段
	  *
	  * @param lineId String 管道ID
	  * @return                       json
	  * 
	 */
	@RequestMapping("/comm/taskSegment.json")
	public void taskSegment(String lineId ,HttpServletResponse response){
//		List data=inspCommService.findTaskSegmen(lineId);

//		ResponseUtil.printl(response, ResponseUtil.getJson(data).toString(), "JSON");
	}
	
	/**
	 * 
	  * 查询 检测任务
	  *
	  * @param lineId String 管道ID
	  * @return                       json
	  * 
	 */
	@RequestMapping("/comm/task.json")
	public void task(String lineId ,String sendPig ,String backPig ,HttpServletResponse response){


		List data=inspCommService.findTask(lineId,sendPig,backPig);
		
		
		ResponseUtil.printl(response, ResponseUtil.getJson(data).toString(), "JSON");
	}

	/**
	 *
	 * 查询 检测任务
	 *
	 * @param lineId String 管道ID
	 * @return                       json
	 *
	 */
	@RequestMapping("/comm/taskByLineId.json")
	public void taskByLineId(String lineId ,HttpServletResponse response){
		List data=inspCommService.taskByLineId(lineId);
		AjaxSupport.sendSuccessText("",data);
//		ResponseUtil.printl(response, ResponseUtil.getJson(data).toString(), "JSON");
	}


	/**
	 *
	 * 查询 检测任务
	 * @param lineId String            管道ID
	 * @param beginMileage BigDecimal 起始里程
	 * @param endMileage BigDecimal   终止里程
	 * @return                       json
	 *
	 */
	@RequestMapping("/comm/taskByLineIdOrMileage.json")
	public void taskByLineIdOrMileage(String lineId ,BigDecimal beginMileage,BigDecimal endMileage,HttpServletResponse response){
		List data=inspCommService.taskByLineIdOrMileage(lineId,beginMileage,endMileage);
		ResponseUtil.printl(response, ResponseUtil.getJson(data).toString(), "JSON");
	}


	@RequestMapping("/comm/getRoomBall.json")
	public void getRoomBall(String lineId , BigDecimal beginMileage, BigDecimal endMileage,String signName, HttpServletResponse response){

		AjaxSupport.sendSuccessText("",pipeLocationService.queryPipeLocation(lineId,beginMileage,endMileage,signName,null));

	}


	@RequestMapping("/comm/newtask.json")
	public void newtask(String taskSegmentId ,HttpServletResponse response){
		List<HashMap<String, Object>> data=inspCommService.taskByLineId(null);

		if(data.size() > 0){
			HashMap<String, Object> map=data.get(0);
			map.put("taskList", inspCommService.taskByLineId((String)map.get("LINEID")));
			AjaxSupport.sendSuccessText("ok", map);
		}else{
			AjaxSupport.sendSuccessText("err", "");
		}
		
		
	}

}
